<template>
  <el-dialog title="停车场列表信息" :visible.sync="parkMsgVisible" center width="720px">
    <el-container>
      <el-main>
        <el-row style="margin-bottom: 10px">
          <el-col :span="10">
            <el-input type="text" v-model="parkName" placeholder="请输入车场名称">
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
          </el-col>
          <el-col :span="1">&nbsp;</el-col>
          <el-col :span="4" style="padding-top: 6px">
            <el-button type="primary" size="mini" style="width: 80px" @click="searchParksMsg">搜索</el-button>
          </el-col>
        </el-row>
        <el-table :data="parkData" v-loading="parkLoad" height="400" :row-class-name="tableRowClassName"
                  style="width: 100%;padding-top: 0px;background-color: #1B4685"
                  @row-dblclick="sendPark">
          <el-table-column property="parkNo" label="停车场编号"></el-table-column>
          <el-table-column property="parkName" label="停车场名称"></el-table-column>
          <el-table-column property="parkTypeName" label="停车场类型"></el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <el-pagination style="margin-top: 16px" background
                       @size-change="handleSizeChangeParkInfo"
                       @current-change="handleCurrentChangeParkInfo"
                       :current-page="pageNum"
                       :page-sizes="[10,20,30, 50]"
                       :page-size="pageSize"
                       :total="total"
                       layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </el-footer>
    </el-container>
  </el-dialog>
</template>

<script>
  import {queryParkingMsg} from '../../../api/parkDataSearch/parkInfoDataSearch'

  export default {
    name: 'parkMsgDialog',
    props: ['parkVisible'],
    data() {
      return {
        pageSize: 20,
        pageNum: 1,
        parkLoad: false,
        parkMsgVisible: false,
        parkData: [],
        parkName: '',
        total: 0
      };
    },
    watch: {
      parkVisible(val) {
        this.parkMsgVisible = val;
        if (val) {
          this.searchParksMsg();
        }
      },
      parkMsgVisible(val) {
        this.$emit('update:parkVisible', val);
      }
    },
    methods: {
      handleSizeChangeParkInfo(val) {
        this.pageSize = val
        this.searchParksMsg();
      },
      handleCurrentChangeParkInfo(val) {
        this.pageNum = val;
        this.searchParksMsg();
      },
      searchParksMsg() {
        this.parkLoad = true;
        console.log(this.pageSize, this.pageNum)
        let parks = {
          parkName: this.parkName,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }
        queryParkingMsg(parks).then(res => {
          for (const index in res.list) {
            if (res.list[index].type === 1) {
              res.list[index].parkTypeName = '道路停车场';
            } else {
              res.list[index].parkTypeName = '封闭停车场';
            }
          }
          this.parkLoad = false;
          this.parkData = res.list;
          this.pageSize = res.pageSize;
          this.pageNum = res.num;
          this.total = res.count;
        });
      },
      sendPark(row, event) {
        this.parkMsgVisible = false;
        this.$emit('parkMsg', row);
      },
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex % 2 === 0) {
          return 'one-row';
        } else {
          return '';
        }
      }
    }
  };
</script>

<style scoped>
</style>
